package com.stellar.circle.controller.admin.sComment;

import com.stellar.circle.controller.admin.sComment.vo.*;
import com.stellar.circle.controller.miniApp.sComment.vo.SCommentTreeResponseVO;
import com.stellar.circle.domain.sComment.SCommentDomainService;

import com.stellar.web.core.bean.PageResult;
import com.stellar.web.core.bean.Result;
import com.stellar.web.core.constants.AuthUserConstants;
import com.stellar.web.core.validator.ValidatorRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评论表控制器
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-05-19 14:52:26
 */
@RequestMapping("/api-admin/sComment")
@RestController("adminSCommentController")
@Slf4j
public class SCommentController {

    @Resource
    private SCommentDomainService sCommentDomainService;

    /**
     * 分页查询评论表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/page")
    public Result<PageResult<SCommentResponseVO>> page(@RequestBody SCommentRequestPageVO requestPageVO) {
        return Result.success(sCommentDomainService.page(requestPageVO));
    }

    /**
     * 获取树形评论
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @GetMapping("/tree")
    public Result<CommentTreeVO> getCommentTree(@RequestParam String sourceType,
                                                @RequestParam Long sourceId) {

        return Result.success(sCommentDomainService.getCommentTree(sourceType, sourceId));
    }


    /**
     * 新增评论表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/create")
    public Result<Boolean> create(@RequestBody SCommentRequestVO requestVO) {
        return Result.success(sCommentDomainService.insert(requestVO));
    }

    /**
     * 修改评论表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody SCommentRequestVO requestVO) {
        return Result.success(sCommentDomainService.update(requestVO));
    }

    /**
     * 删除评论表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.success(sCommentDomainService.delete(id));
    }

    /**
     * 获取评论表详情
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @GetMapping("/get/{id}")
    public Result<SCommentResponseVO> get(@PathVariable("id") Long id) {
        return Result.success(sCommentDomainService.get(id));
    }

    /**
     * 获取评论数据统计
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/countByCondition")
    public Result<SCommentDataStatisticsVO> countByCondition(@RequestBody(required = false) SCommentRequestVO sCommentRequestVO) {
        return Result.success(sCommentDomainService.countByCondition(sCommentRequestVO));
    }


    /**
     * 获取过去一周内每天的评论数 (前端绘制折线图)
     *
     * @return
     */
    @ValidatorRole()
    @GetMapping("/daily-statistics")
    public Result<List<DailyCommentStatisticsVO>> getDailyCommentStatistics() {

        List<DailyCommentStatisticsVO> statistics =
                sCommentDomainService.getDailyCommentStatistics();

        return Result.success(statistics);
    }


}
